package com.szosen.jkzj.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.AdapterView.OnItemSelectedListener;

import com.google.gson.Gson;
import com.szosen.application.MyApplication;
import com.szosen.jkzj.R;
import com.szosen.json.PastHistorylist;
import com.szosen.util.JibingContants;

public class JiBingActivity extends BaseActivity {
	private Spinner sp_jwslb;
	private String[] array_jwslb_s;
	private ArrayAdapter<String> adapter_jwslb;
	private Spinner sp_gcff;
	private String[] array_gcffs;
	private ArrayAdapter<String> adapter_gcff;
	private Spinner sp_jbmc;
	private String[] array_jbmcs;
	private ArrayAdapter<String> adapter_jbmc;
	private Spinner sp_zgqk;
	private String[] array_zgqks;
	private ArrayAdapter<String> adapter_zgqk;
	private EditText jibing_et_fhcs, jibing_et_jgms, jibing_et_qsrq,
			jibing_et_zzrq, jibing_et_qzrq, jibing_et_jljg, jibing_et_jlys,
			jibing_et_jlrq, jibing_et_zhxgr, jibing_et_zhxgdw,
			jibing_et_zhxgrq;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.jkda_item_layout_jibing);
		initView();
	}

	public void addJWS(View view) {
		PastHistorylist list = new PastHistorylist();
		// list.setPastHisTypeCode(jibing_et_dab);//档案编号
		// list.setEmpiId("");//创业唯一标识
		// 这里需要将名称和对应的编码对应起来才行。
		String gcff = ((String) sp_gcff.getSelectedItem()).trim();
		String jwslb = ((String) sp_jwslb.getSelectedItem()).trim();
		String jbmc = ((String) sp_jbmc.getSelectedItem()).trim();
		String zgqk = ((String) sp_zgqk.getSelectedItem()).trim();
		list.setPastHisTypeCode(JibingContants.getCodeByJWSLB(jwslb));
		list.setMethodsCode(JibingContants.getCodeByGCFF(gcff));// 观测方法
		list.setProtect(getTextByEt(jibing_et_fhcs));
		list.setDiseaseCode(JibingContants.getCodeByBM(jwslb,jbmc));// 疾病的代码
		list.setDiseaseText(getTextByEt(jibing_et_jgms));// 结果描述
		list.setVestingCode(JibingContants.getCodeByZGQK(zgqk));
		list.setStartDate(getTextByEt(jibing_et_qsrq));// 起始日期
		list.setEndDate(getTextByEt(jibing_et_zzrq));// 终止日期
		list.setConfirmDate(getTextByEt(jibing_et_qzrq));// 确诊日期
		
		list.setRecordUnit(MyApplication.getOngovId());// 记录机构
		list.setRecordUser(MyApplication.getOnDoctorId());// 记录医生
		list.setRecordDate(getTextByEt(jibing_et_qzrq));// 记录日期
		list.setLastModifyUser(MyApplication.getOnDoctorId());// 最后修改人
		list.setLastModifyUnit(MyApplication.getOngovId());// 最后修改单位
		list.setLastModifyDate(getTextByEt(jibing_et_qzrq));// 最后修改日期
		Gson gson = new Gson();
		String str = gson.toJson(list);
		Intent intent = new Intent();
		// 将json字符串返回到原JKDAactivity
		intent.putExtra(JKDAActivity.RESULTDATA_JIBINGDATA, str);
		intent.putExtra(JKDAActivity.JWSLB, jwslb);
		intent.putExtra(JKDAActivity.GCFF, gcff);
		intent.putExtra(JKDAActivity.JBMC, jbmc);
		intent.putExtra(JKDAActivity.ZGQK, zgqk);
		setResult(JKDAActivity.RESULTCODE_JIBINGDATA, intent);
		finish();
	}

	public void cancel(View view) {
		finish();
	}

	private void initView() {
		jibing_et_fhcs = (EditText) findViewById(R.id.jibing_et_fhcs);
		jibing_et_jgms = (EditText) findViewById(R.id.jibing_et_jgms);
		jibing_et_qsrq = (EditText) findViewById(R.id.jibing_et_qsrq);
		jibing_et_zzrq = (EditText) findViewById(R.id.jibing_et_zzrq);
		jibing_et_qzrq = (EditText) findViewById(R.id.jibing_et_qzrq);
		jibing_et_jljg = (EditText) findViewById(R.id.jibing_et_jljg);
		jibing_et_jlys = (EditText) findViewById(R.id.jibing_et_jlys);
		jibing_et_jlrq = (EditText) findViewById(R.id.jibing_et_jlrq);
		jibing_et_zhxgr = (EditText) findViewById(R.id.jibing_et_zhxgr);
		jibing_et_zhxgdw = (EditText) findViewById(R.id.jibing_et_zhxgdw);
		jibing_et_zhxgrq = (EditText) findViewById(R.id.jibing_et_zhxgrq);

		sp_jwslb = (Spinner) findViewById(R.id.jibing_sp_jwslb);
		array_jwslb_s = JibingContants.JWSLB.names;
		adapter_jwslb = new ArrayAdapter<String>(this,
				R.layout.login_spinner_item, array_jwslb_s);
		adapter_jwslb
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		sp_jwslb.setAdapter(adapter_jwslb);
		sp_jwslb.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				switch (position) {
				case 0:
					array_jbmcs = JibingContants.BM.YWGMS.items;
					break;
				case 1:
					array_jbmcs = JibingContants.BM.JBS.items;
					break;
				case 2:
					array_jbmcs = JibingContants.BM.SSS.items;
					break;
				case 3:
					array_jbmcs = JibingContants.BM.SXS.items;
					break;
				case 4:
					array_jbmcs = JibingContants.BM.YCBS.items;
					break;
				case 5:
					array_jbmcs = JibingContants.BM.WSS.items;
					break;
				case 6:
					array_jbmcs = JibingContants.BM.JZJBS_FQ.items;
					break;
				case 7:
					array_jbmcs = JibingContants.BM.JZJBS_MQ.items;
					break;
				case 8:
					array_jbmcs = JibingContants.BM.JZJBS_XDJM.items;
					break;
				case 9:
					array_jbmcs = JibingContants.BM.JZJBS_ZN.items;
					break;
				case 10:
					array_jbmcs = JibingContants.BM.CJZK.items;
					break;
				case 11:
					array_jbmcs = JibingContants.BM.BLS.items;
					break;

				default:
					break;
				}
				adapter_jbmc = new ArrayAdapter<String>(JiBingActivity.this,
						R.layout.login_spinner_item, array_jbmcs);
				adapter_jbmc
						.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
				sp_jbmc.setAdapter(adapter_jbmc);
			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {

			}
		});
		sp_jwslb.setSelection(0);
		sp_gcff = (Spinner) findViewById(R.id.jibing_sp_gcff);
		array_gcffs = JibingContants.GCFF.names;
		adapter_gcff = new ArrayAdapter<String>(this,
				R.layout.login_spinner_item, array_gcffs);
		adapter_gcff
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		sp_gcff.setAdapter(adapter_gcff);
		sp_gcff.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {

			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {
			}
		});
		sp_gcff.setSelection(0);

		sp_jbmc = (Spinner) findViewById(R.id.jibing_sp_bm);
		array_jbmcs = JibingContants.BM.JBS.items;
		adapter_jbmc = new ArrayAdapter<String>(this,
				R.layout.login_spinner_item, array_jbmcs);
		adapter_jbmc
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		sp_jbmc.setAdapter(adapter_jbmc);
		sp_jbmc.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {

			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {
			}
		});
		sp_jbmc.setSelection(0);

		sp_zgqk = (Spinner) findViewById(R.id.jibing_sp_zgqk);
		array_zgqks = JibingContants.ZGQK.names;
		adapter_zgqk = new ArrayAdapter<String>(this,
				R.layout.login_spinner_item, array_zgqks);
		adapter_zgqk
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		sp_zgqk.setAdapter(adapter_zgqk);
		sp_zgqk.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {

			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {
			}
		});
		sp_zgqk.setSelection(0);
	}
}
